/**
 * CategoryPane.java
 * @author: liuex
 * 2007-12-31 ����02:54:19
 *
 * note: 
 */
package lex.mtd.ui;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;

public class CategoryTree extends JTree {
	private DefaultMutableTreeNode rootNode = null;

	public CategoryTree() {
		super();
		this.initialize();
	}

	private void initialize()
	{
		this.setModel( new DefaultTreeModel( this.getRootNode() ) );
		this.setCellRenderer( new DefaultTreeCellRenderer(){
			@Override
			public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel,
				boolean expanded, boolean leaf, int row, boolean hasFocus )
			{
				return super.getTreeCellRendererComponent( tree, value, sel, expanded, false, row,
					hasFocus );
			}
		} );
	}

	private DefaultMutableTreeNode getRootNode()
	{
		if( null == rootNode )
		{
			rootNode = new DefaultMutableTreeNode( "Category" );
			Category[] categories = Category.values();
			for( Category c : categories )
				rootNode.add( new DefaultMutableTreeNode( c.name() ) );
		}
		return rootNode;
	}
}
